// api/Api.js
/**
 \* Created with 微信开发者工具.
 \* @author: 龙威
 \* @time: 2019/5/30 10:14
 \* Description: 请求封装
 \*/

import Ajax from './Ajax'


/**
 * 小程序请求IP模式，部署时将dev改prod
 */
// const appRequest = {
//   mode: "dev",
//   prodIp: "",
//   devIp: "https://10.39.40.182:444/api/wx"
// }

const app = getApp();
const requestIp = app.globalData.appRequest.mode === "dev" ? app.globalData.appRequest.devIp : app.globalData.appRequest.prodIp;
// const requestIp = appRequest.mode === "dev" ? appRequest.devIp : appRequest.prodIp;

export default {
  user: {
    /**
     * 登录
     * @params: {userVo}
     */
    login(params) {
      return Ajax.post(requestIp + "/user/login", params);
    },

    /**
     * 注册
     * @params: {userVo}
     */
    register(params) {
      return Ajax.post(requestIp + "/user/register", params);
    },

    /**
     * 发送手机验证码
     */
    sendMsgValidateCode(params) {
      return Ajax.get(requestIp + "/phone/validate", params);
    }
  },

  questionnaire: {
    /**
     * 获得问卷
     */
    getQuestionnaire(params) {
      return Ajax.get(requestIp + "/questionnaire", params);
    }
  },

  survey: {
    /**
     * 获得问卷调查的统计
     * @params: userId:
     */
    getSurveyCount(params) {
      return Ajax.get(requestIp + "/survey/count", params);
    },

    /**
     * 获得评分
     * @params: userSurveyVo
     */
    getCalculateSurveyResultGrades(params) {
      return Ajax.post(requestIp + "/user/survey/grades", params);
    },

    /**
     * 完成调查
     */
    doneSurvey(params) {
      return Ajax.post(requestIp + "/user/survey/done", params);
    },

    /**
     * 获得用户调查信息
     */
    getUserSurvey(params) {
      return Ajax.get(requestIp + "/user/survey/detail", params);
    },

    /**
     * 问卷列表
     * @params: isdone: 0, 1
     * @params: userId: 
     */
    listSurveys(params) {
      return Ajax.get(requestIp + "/survey/list", params);
    }
  },
  
  weixin: {
    /**
     * 提供消息ID
     * @params:
     */
    offerFormId(params) {
      return Ajax.get(requestIp + "", params);
    },
    /**
     * 获取openid
     * @params: {code, secretCode, appid}
     */
    getOpenId(params) {
      return Ajax.get(requestIp + "/wxapi/openid", params);
    }
  }
}